package org.budo.mongo.jdbc.driver.resultset;

import java.sql.SQLException;

import org.budo.mongo.jdbc.driver.BudoMongoJdbcResultSet;

/**
 * 数据放在二维数组里面
 * 
 * @author li
 */
public class RowsResultSet extends BudoMongoJdbcResultSet {
    private Object[][] dataRows;

    private int currentRowIndex = -1;

    public void setResultSetData(Object[][] dataRows) {
        this.dataRows = dataRows;
    }

    public boolean next() throws SQLException {
        if (null == this.dataRows) {
            return false;
        }

        this.currentRowIndex++;
        return this.dataRows.length > this.currentRowIndex;
    }

    /**
     * @see #wasNull()
     */
    public Object getObject(int columnIndex) throws SQLException {
        Object value = dataRows[currentRowIndex][columnIndex - 1];
        if (null == value) {
            this.setLastGotValueWasNull(true);
        }
        return value;
    }
}